#include "pch.h"

#include "iosystem/mime.h"
#include "helper/array.h"



namespace IO
{

	///
	MIME::MIME()
	{

	}


	///
	MIME::MIME(const Helper::String & both)
	{
		this->Split(both);
	}


	///
	MIME::MIME(const Helper::String &type, const Helper::String &subtype):
	m_type(type),
		m_subType(subtype)
	{

	}


	///
	MIME::MIME(const MIME & rhs):
	m_type(rhs.m_type),
		m_subType(rhs.m_subType)
	{

	}



	///
	void MIME::operator =(const IO::MIME &rhs)
	{
		this->m_type = rhs.m_type;
		this->m_subType = rhs.m_subType;
	}


	///
	bool MIME::operator ==(const IO::MIME &rhs) const
	{
		return ((this->m_type == rhs.m_type) &&
			(this->m_subType == rhs.m_subType));
	}


	///
	bool MIME::operator !=(const IO::MIME &rhs) const
	{
		return ((this->m_type != rhs.m_type) ||
			(this->m_subType != rhs.m_subType));
	}





	///
	void MIME::Set(const Helper::String &both)
	{
		this->Split(both);
	}


	///
	void MIME::Set(const Helper::String & type, const Helper::String & subtype)
	{
		this->m_type = type;
		this->m_subType = subtype;
	}


	///
	const Helper::String & MIME::Get() const
	{
		return this->Bind();
	}


	///
	const Helper::String & MIME::GetSubType() const
	{
		return this->m_subType;
	}


	///
	const Helper::String & MIME::GetType() const
	{
		return this->m_type;
	}


	///
	bool MIME::IsValid() const 
	{
		return (this->m_type.IsValid() && this->m_subType.IsValid());
	}





	///
	const Helper::String & MIME::Bind() const
	{
		Helper::String * result = new Helper::String(this->m_type);

		result->Add("|");
		result->Add(this->m_subType);

		return *result;
	}


	///
	void MIME::Split(const Helper::String &both)
	{
		Helper::Array<Helper::String> temp = both.Tokenize("|");

		this->m_type = temp[0];
		this->m_subType = temp[1];
	}

}